package org.example.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.example.entity.DeliveryAddress;
import org.example.service.DeliveryAddressService;
import java.util.List;

@RestController
@RequestMapping("/deliveryaddress")
public class DeliveryAddressController {

    @Autowired
    private DeliveryAddressService deliveryAddressService;

    // 1. 根据用户编号查询所属送货地址
    @GetMapping("/listDeliveryAddressByUserId")
    public List<DeliveryAddress> listDeliveryAddressByUserId(@RequestParam("userId") String userId) {
        return deliveryAddressService.listDeliveryAddressByUserId(userId);
    }

    // 2. 根据送货地址编号查询送货地址
    @GetMapping("/getDeliveryAddressById")
    public DeliveryAddress getDeliveryAddressById(@RequestParam("daId") Integer daId) {
        return deliveryAddressService.getDeliveryAddressById(daId);
    }

    // 3. 向送货地址表中添加一条记录
    @PostMapping("/saveDeliveryAddress")
    public int saveDeliveryAddress(@RequestBody DeliveryAddress deliveryAddress) {
        return deliveryAddressService.saveDeliveryAddress(deliveryAddress);
    }

    // 4. 根据送货地址编号更新送货地址信息
    @PutMapping("/updateDeliveryAddress")
    public int updateDeliveryAddress(@RequestBody DeliveryAddress deliveryAddress) {
        return deliveryAddressService.updateDeliveryAddress(deliveryAddress);
    }

    // 5. 根据送货地址编号删除一条记录
    @DeleteMapping("/removeDeliveryAddress")
    public int removeDeliveryAddress(@RequestParam("daId") Integer daId) {
        return deliveryAddressService.removeDeliveryAddress(daId);
    }
}